package uk.ac.cam.echo.messages;

import java.util.Date;

import uk.ac.cam.echo.app.DBInt;

public class CheckInMessage extends Message implements Comparable<CheckInMessage> {

	private static final long serialVersionUID = 1L;

	private final int m_AttractionID;
	private final String m_AttractionName;
	private String m_Name;
	private final long m_Time;

	public CheckInMessage(String rfid, int attractionID, String attractionName, long time) {
		super(rfid);
		this.m_AttractionID = attractionID;
		this.m_AttractionName = attractionName;
		this.m_Time = time;	
	}
	
	public int getAttractionID() {
		return this.m_AttractionID;
	}
	
	public String getAttractionName() {
		return this.m_AttractionName;
	}
	
	public long getCheckInTime() {
		return this.m_Time;
	}
	
	public String getFormattedCheckInTime() {
		return DBInt.ShortDateFormat.format(new Date(getCheckInTime()));
	}
	
	public String getName() {
		return this.m_Name;
	}
	
	public void setName(String name) {
		this.m_Name = name;
	}
	
	@Override
	public String toString() {
		return DBInt.ShortDateFormat.format(new Date(this.getCheckInTime())) + " " + this.getName() + " checked in at " + this.getAttractionName();
	}

	@Override
	public int compareTo(CheckInMessage c) {
		final int BEFORE = -1;
		final int EQUAL = 0;
		final int AFTER = 1;
		
		long me = this.getCheckInTime();
		long you = c.getCheckInTime();
		
		if (me == you)
			return EQUAL;
		else if (me < you) 
			return BEFORE;
		else
			return AFTER;
	}

}
